﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.cn
{
    public partial class orderlist : System.Web.UI.Page
    {
        // Fields
        public string ordermsg = "";

        // Methods
        private void Bind()
        {
            string str;
            string str3 = "";
            //if ((this.Session["username"] != null) && (base.Request.Form["orderkey"] != null))
            //{
            //    str = string.Concat(new object[] { "select orderid,ordercode,cname,pay,totalprice,states,ordertime,paytime,shiptime,sendCompany,sendCode from DB_Order where memberid=", this.Session["memberid"], " and ordercode='", base.Request.Form["orderkey"], "' or tel='" + base.Request.QueryString["linkWay"] + "' or phone='" + base.Request.QueryString["phone"] + "'" });
            //}
            //else 
                if (this.Session["username"] != null)
            {
                str = "select orderid,ordercode,cname,pay,totalprice,states,ordertime,paytime,shiptime,sendCompany,sendCode from DB_Order where memberid=" + this.Session["memberid"] ;
            }
            else
            {
            string sWhere = string.Empty;
            if (!string.IsNullOrEmpty(base.Request.QueryString["orderKey"]))
            {
                sWhere = "ordercode='" + base.Request.QueryString["orderKey"] + "'";
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["linkWay"]))
            {
                if (sWhere == string.Empty)
                {
                    sWhere = " tel1='" + base.Request.QueryString["linkWay"] + "'" + " or phone1='" + base.Request.QueryString["linkWay"] + "'";
                }
                else
                {
                    sWhere = sWhere + " or tel='" + base.Request.QueryString["linkWay"] + "'" + " or phone='" + base.Request.QueryString["linkWay"] + "'";
                }
            }
            str = "select orderid,ordercode,cname,pay,totalprice,states,ordertime,paytime,shiptime,sendCompany,sendCode from DB_Order where " + sWhere;
            }
            DataTable table = SQLAccess.GreatDs(str).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.ordermsg = this.ordermsg + "<tr>";
                    string ordermsg = this.ordermsg;
                    this.ordermsg = ordermsg + "<td height='28' align='center' bgcolor='#FFFFFF'><a href='order_details.aspx?oid=" + row["orderid"].ToString() + "' target=_blank>" + row["ordercode"].ToString() + "</a></td>";
                  
                 //   this.ordermsg = this.ordermsg + "定单总金额 : <span class='text_red'>" + string.Format("{0:f}", Convert.ToSingle(row["totalprice"])) + " 元</span></div></td>";
                    if (row["states"].ToString() == "1")
                    {
                        str3 = "备货中";
                    }
                    else if (row["states"].ToString() == "2")
                    {
                        str3 = "已发货";
                    }
                    else if (row["states"].ToString() == "3")
                    {
                        str3 = "已完成";
                    }
                    else if (row["states"].ToString() == "5")
                    {
                        str3 = "已取消";
                    }
                    else
                    {
                        str3 = "新定单";
                    }
                   
                    this.ordermsg = this.ordermsg + "<td align='center' bgcolor='#FFFFFF'><span class='text_red'><font color='red'>" + str3 + "</font></span><br />"
                                                  + row["ordertime"].ToString() + " </td>";
                     this.ordermsg = this.ordermsg + "<td align='left' bgcolor='#FFFFFF'><div style='margin:5px; text-align:left;'>物流:<span class='text_red'>" + row["sendCompany"].ToString() + "</span> <br />"
                                                       +"物流号:" + row["sendCode"].ToString() + "<br />";
                  
                    this.ordermsg = this.ordermsg + "</span></div></td></tr>";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

             this.Bind();
        }

    }
}